﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TankController.Dominio;

namespace TankController
{
    public partial class Serie : UserControl
    {
        private Grafico grafico;

        private ISinal sinal;

        internal Serie(Grafico grafico, ISinal sinal, Color cor)
        {
            InitializeComponent();

            this.grafico = grafico;

            this.sinal = sinal;
            this.pnlCor.BackColor = cor;

            this.lblNomeSinal.Text = sinal.Descricao;
        }

        private void cbxCor_CheckedChanged(object sender, EventArgs e)
        {
            if (cbxCor.Checked)
            {
                grafico.AdicionarSinal(this, sinal, pnlCor.BackColor);

                //DesabilitarOpcoes(cbx);
            }
            else
            {
                grafico.RemoverSinal(sinal, pnlCor.BackColor);

                //HabilitarOpcoes();
            }
        }

        /*private void RemoverAnterior(CheckBox cbx, Color cor)
        {
            foreach (CheckBox outroCbx in this.Controls.OfType<CheckBox>())
            {
                if (outroCbx != cbx && outroCbx.Checked)
                {
                    outroCbx.Checked = false;

                    break;
                }
            }
        }*/

        /*private void HabilitarOpcoes()
        {
            foreach (CheckBox cbx in this.Controls.OfType<CheckBox>())
            {
                cbx.Enabled = true;
            }
        }

        private void DesabilitarOpcoes(CheckBox cbx)
        {
            foreach (CheckBox outroCbx in this.Controls.OfType<CheckBox>())
            {
                if (outroCbx != cbx)
                {
                    outroCbx.Enabled = false;
                }
            }
        }*/

        /*internal void HabilitarCor(Color cor)
        {
            CheckBox cbx = this.Controls.Find("cbx" + this.Controls.OfType<Panel>().Single(c => c.BackColor == cor).Name.Replace("pnl", ""), false)[0] as CheckBox;

            cbx.Enabled = true;
        }

        internal void DesbilitarCor(Color cor)
        {
            CheckBox cbx = this.Controls.Find("cbx" + this.Controls.OfType<Panel>().Single(c => c.BackColor == cor).Name.Replace("pnl", ""), false)[0] as CheckBox;

            cbx.Enabled = false;
        }*/

        private void pnlCor_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                cbxCor.Checked = !cbxCor.Checked;
            }
        }

        private void lblNomeSinal_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                cbxCor.Checked = !cbxCor.Checked;
            }
        }

        internal void Marcar()
        {
            cbxCor.Checked = true;
        }
    }
}
